<template>
  <div class="header_bar">
    <div class="bar_left" @click="toIndex">自助停车</div>
    <div class="bar_right">
      <span class="bar_item" v-for="(item, index) in barList" :key="index" :style="item.borderBottom" @click="toOther(item,index)">{{
          item.name
        }}</span>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      barList: [
        {name: '主页', path: '/index', borderBottom: ''},
        {name: '入停车场', path: '/enterPark', borderBottom: ''},
        {name: '出停车场', path: '/outPark', borderBottom: ''},
      ],
      keyWord: '',
    }
  },

  mounted() {
    let token = window.localStorage.getItem('access_token')
    if(token){
      this.barList.push({name: '个人中心', path: '/userCenter', borderBottom: ''})
    }else{
      this.barList.push({name: '登录', path: '/login', borderBottom: ''})
    }
    for (let iterator of this.barList) {
      if (iterator.path == this.$route.path) {
        iterator.borderBottom = "border-bottom: 2px solid #fe4801;"
      } else {
        iterator.borderBottom = ""
      }
      if(this.$route.path=='/'){
        this.barList[0].borderBottom = 'border-bottom: 2px solid #fe4801;'
      }
    }
  },
  methods: {
    searchService() {
    },
    toOther(item,index){
      if(index=='0'){
        this.$router.push('/')
      }else{
        this.$router.push({
          path: item.path
        });
      }
    },
    toIndex(){
      this.$router.push('/')
    }
  }
}
</script>
<style scoped>
.header_bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: #022f4a;
  color: #fff;
  padding: 15px 0;
  font-family: "Roboto", sans-serif;
  padding-right: 25px;
  padding-left: 25px;
  cursor: pointer;
}

.bar_left {
  padding-top: 0.3125rem;
  padding-bottom: 0.3125rem;
  margin-right: 1rem;
  font-size: 1.25rem;
  line-height: inherit;
  font-weight: bold;
  white-space: nowrap;
}

.bar_item {
  margin: 0px 25px;
  color: #ffffff;
  text-align: center;
  padding-bottom: 5px;
  cursor: pointer;
}

.el-input-group {
  width: 200px;
}
</style>
